<template>
	<view class="content">
		<view class="setListBox">
			<view class="leftSet">
				<image src="/static/icons/clock.svg" mode=""></image>
				<view class="text">传感器无人判定时间</view>
			</view>
			<view class="rightSet">
				<view class="selectSet">
					<uni-data-select v-model="valueTime" :localdata="rangeTime" @change="changeTime" placeholder=""
						:clear="false"></uni-data-select>
				</view>
				<view class="confirm" @click="confirm('time')">确认</view>
			</view>
		</view>
		<view class="setListBox">
			<view class="leftSet">
				<image src="/static/icons/sgq.svg" mode=""></image>
				<view class="text">传感器无人判定距离</view>
			</view>
			<view class="rightSet">
				<view class="selectSet">
					<uni-data-select v-model="valueDistance" :localdata="rangeDistance" @change="changeDistance"
						placeholder="" :clear="false"></uni-data-select>
				</view>
				<view class="confirm" @click="confirm('cgqDistance')">确认</view>
			</view>
		</view>
		<view class="setListBox">
			<view class="leftSet">
				<image src="/static/icons/hot2c2c2c.svg" mode=""></image>
				<view class="text">无人判定后制热模式工作状态</view>
			</view>
			<view class="rightSet">
				<view class="selectSet">
					<uni-data-select v-model="valueHeating" :localdata="rangeHeating" @change="changeHeating"
						placeholder="" :clear="false"></uni-data-select>
				</view>
				<view class="confirm" @click="confirm('rangeHotHeating')">确认</view>
			</view>
		</view>
		<view class="setListBox">
			<view class="leftSet">
				<image src="/static/icons/cold2a1ee5.svg" mode=""></image>
				<view class="text">无人判定后制冷模式工作状态</view>
			</view>
			<view class="rightSet">
				<view class="selectSet">
					<uni-data-select v-model="valueColding" :localdata="rangeColding" @change="changeColding"
						placeholder="" :clear="false"></uni-data-select>
				</view>
				<view class="confirm" @click="confirm('rangeCold')">确认</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'

	const valueTime = ref(2);
	const rangeTime = ref([]);
	const deviceEquipNo = ref('')
	const id = ref('')



	// 判定距离
	const valueDistance = ref(2);
	const rangeDistance = ref([]);
	// 制冷
	const valueColding = ref(0);
	const rangeColding = ref([]);
	// 制热
	const valueHeating = ref(0);
	const rangeHeating = ref([]);

	const details = ref({})
	onShow(() => {
		rangeTime.value = [];
		for (let i = 2; i <= 60; i++) {
			rangeTime.value.push({
				text: i, // 显示带单位
				value: i
			});
		}

		rangeDistance.value = uni.getStorageSync('sys_cgqDistance').map(item => ({
			text: item.dictLabel,
			value: Number(item.dictValue)
		}));
		rangeHeating.value = uni.getStorageSync('sys_kt_noHeatTemp').map(item => ({
			text: item.dictLabel,
			value: Number(item.dictValue)
		}));
		rangeColding.value = uni.getStorageSync('sys_kt_noCoolTemp').map(item => ({
			text: item.dictLabel,
			value: Number(item.dictValue)
		}));
	})
	onLoad((options) => {
		deviceEquipNo.value = decodeURIComponent(options.equipNo);
		id.value = decodeURIComponent(options.id)
		getDevInfo(id.value)
	});
	const getDevInfo = (devId) => {
		let data = {
			id: Number(devId)
		}
		uni.$u.http.post('/wechat/getDevInfo', data).then(res => {
			if (res.success) {
				console.log(res.data, "人存设置")
				details.value = res.data;
				valueTime.value = Number(res.data.cgqTime)
				valueDistance.value = Number(res.data.cgqDistance)
				valueHeating.value = Number(res.data.noHeatTemp)
				valueColding.value = Number(res.data.noCoolTemp)
			}
		})
	}
	// 判定时间e
	const changeTime = (e) => {
		valueTime.value = e
		console.log(e, "333")
	};

	const changeDistance = (e) => {

	};
	const confirm = (val) => {
		let param = {}
		if (val == 'time') {
			param = {
				equipNo: deviceEquipNo.value,
				cgqTime: valueTime.value,
				id: Number(id.value)
			}
		}
		if (val == 'cgqDistance') {
			param = {
				equipNo: deviceEquipNo.value,
				cgqDistance: valueDistance.value,
				id: Number(id.value)
			}
		}
		if (val == 'rangeHotHeating') {
			param = {
				equipNo: deviceEquipNo.value,
				noHeatTemp: valueHeating.value,
				id: Number(id.value)
			}
		}
		if (val == 'rangeCold') {
			param = {
				equipNo: deviceEquipNo.value,
				noCoolTemp: valueColding.value,
				id: Number(id.value)
			}
		}
		uni.$u.http.post('/wechat/editSend', param).then((res) => {
			if (res.success) {
				uni.showToast({
					title: '设置成功',
					icon: 'success'
				})
			}
		})
	}



	const changeHeating = (e) => {
		console.log("e:", e);
	};



	const changeColding = (e) => {
		console.log("e:", e);
	};
</script>

<style lang="scss" scoped>
	.setListBox {
		width: 100%;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.leftSet {
			margin-left: 40rpx;
			display: flex;
			align-items: center;

			image {
				width: 20rpx;
				height: 20rpx;
			}

			.text {
				font-size: 30rpx;
				color: #a7a7a7;
			}
		}

		.rightSet {
			margin-right: 20rpx;
			display: flex;
			align-items: center;

			.confirm {
				width: 100rpx;
				height: 35px;
				background-color: #00aaff;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #fff;
				font-size: 28rpx;
				margin-left: 20rpx;
			}

			.selectSet {
				width: 150rpx;
			}

			select {
				border-color: #00aaff !important;
				border-radius: 4rpx;
			}
		}
	}
</style>